package com.azzcs.myrpc.autoconfig;

import com.azzcs.myrpc.register.ServerRegister;
import com.azzcs.myrpc.register.ZookeeperServerRegister;
import com.azzcs.myrpc.serializer.JSONSerializer;
import com.azzcs.myrpc.serializer.Serializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: wzg
 * @Date: 2021/1/23 上午10:08
 */
@Configuration
public class MyRpcAutoConfig {
    @Value("${rpc.registry.address}")
    private String registryAddress;

    @Bean
    @ConditionalOnMissingBean(type = "com.azzcs.myrpc.serializer.Serializer")
    public Serializer serializer() {
        return new JSONSerializer();
    }

    @Bean
    @ConditionalOnMissingBean(type = "com.azzcs.myrpc.register.ServerRegister")
    public ServerRegister serverRegister() {
        return new ZookeeperServerRegister(registryAddress);
    }

}
